Page({
  data: {
    technicianId: '',
    technician: {
      id: 1,
      name: '张技师',
      avatar: '/assets/images/technician1.jpg',
      rating: 4.8,
      serviceArea: '北京市朝阳区',
      orderCount: 128,
      experience: '拥有10年按摩经验，专业提供全身放松按摩、足底按摩等服务，手法娴熟，深受客户好评。'
    },
    services: [
      {
        id: 1,
        name: '全身放松按摩',
        image: '/assets/images/service1.jpg',
        duration: 60,
        price: 198
      },
      {
        id: 2,
        name: '足底按摩',
        image: '/assets/images/service2.jpg',
        duration: 45,
        price: 128
      },
      {
        id: 3,
        name: '肩颈按摩',
        image: '/assets/images/service3.jpg',
        duration: 30,
        price: 88
      }
    ],
    reviews: [
      {
        id: 1,
        reviewer: '李先生',
        stars: [true, true, true, true, true],
        content: '技师手法专业，服务态度很好，非常满意！',
        time: '2023-05-15'
      },
      {
        id: 2,
        reviewer: '王女士',
        stars: [true, true, true, true, false],
        content: '环境舒适，按摩效果不错，会再次预约。',
        time: '2023-05-10'
      }
    ],
    selectedService: null
  },

  onLoad: function(options) {
    if (options.id) {
      this.setData({
        technicianId: options.id
      });
      this.loadTechnicianDetail(options.id);
    }
  },

  loadTechnicianDetail: function(id) {
    const app = getApp();
    
    // 获取技师详情
    app.request({
      url: `${app.globalData.baseUrl}/technicians/${id}/`,
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            technician: res.data
          });
        }
      }
    });
    
    // 获取技师提供的服务
    app.request({
      url: `${app.globalData.baseUrl}/technicians/${id}/services/`,
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            services: res.data
          });
        }
      }
    });
  },

  selectService: function(e) {
    const serviceId = e.currentTarget.dataset.id;
    const service = this.data.services.find(s => s.id == serviceId);
    this.setData({
      selectedService: service
    });
  },

  bookService: function() {
    if (!this.data.selectedService) {
      wx.showToast({
        title: '请选择服务项目',
        icon: 'none'
      });
      return;
    }
    
    // 跳转到预约确认页面
    wx.navigateTo({
      url: `/pages/customer/orderConfirm?technicianId=${this.data.technicianId}&serviceId=${this.data.selectedService.id}`
    });
  },

  viewAllReviews: function() {
    wx.navigateTo({
      url: `/pages/customer/technicianReviews?id=${this.data.technicianId}`
    });
  }
})